// pages/index/answer/list/list.js
const app = getApp()
Page({
  data: {
    questionId: '',
    question: '',
    url: '',
    reply: ''
  },
  onLoad() {
    this.setData({
      url: app.globalData.URL
    });
    const eventChannel = this.getOpenerEventChannel();
    const that = this;
    eventChannel.on('onlineDetail', function (data) {
      that.setData({
        questionId: data.id
      }, () => {
        wx.request({
          url: `${that.data.url}/question/selectById/${that.data.questionId}`,
          method: 'GET',
          success: (resp) => {
            that.setData({
              question: resp.data.data
            })
            wx.request({
              url: `${that.data.url}/reply/select/`,
              method: 'POST',
              data: {
                pageNum: 1,
                pageSize: 10000,
                questionId: that.data.questionId,
              },
              success(resp) {
                that.setData({
                  reply: resp.data.data.list
                })
                console.log(that.data.reply);
              }
            })
          },
          fail: (err) => {
            console.error('请求失败：', err);
          }
        });
      });
    });
  },
  toAnswer() {
    wx.navigateTo({
      url: `/pages/index/answer/answer?questionId=${this.data.questionId}`,
    })
  },
})